import request from '@/utils/request'

// 设备管理API
export function getDeviceList(query) {
  return request({
    url: '/customer/device/list',
    method: 'get',
    params: query
  })
}

// 获取设备详细信息
export function getDeviceById(deviceId) {
  return request({
    url: '/customer/device/' + deviceId,
    method: 'get'
  })
}

// 新增设备
export function createDevice(data) {
  return request({
    url: '/customer/device',
    method: 'post',
    data: data
  })
}

// 修改设备
export function updateDevice(deviceId, data) {
  return request({
    url: '/customer/device/' + deviceId,
    method: 'put',
    data: data
  })
}

// 删除设备
export function deleteDevice(deviceId) {
  return request({
    url: '/customer/device/' + deviceId,
    method: 'delete'
  })
}

// 批量删除设备
export function batchDeleteDevices(deviceIds) {
  return request({
    url: '/customer/device/batch',
    method: 'delete',
    data: deviceIds
  })
}

// 获取设备分页列表
export function getDevicePage(query) {
  return request({
    url: '/customer/device/page',
    method: 'get',
    params: query
  })
}

// 更新设备状态
export function updateDeviceStatus(deviceId, status) {
  return request({
    url: '/customer/device/' + deviceId + '/status',
    method: 'put',
    data: { status }
  })
}

// 获取设备统计信息
export function getDeviceStats() {
  return request({
    url: '/customer/device/stats',
    method: 'get'
  })
}

// 重新生成设备密钥
export function regenerateDeviceKey(deviceId) {
  return request({
    url: '/customer/device/' + deviceId + '/regenerate-key',
    method: 'post'
  })
}

// 获取设备密钥信息
export function getDeviceKeys(deviceId) {
  return request({
    url: '/customer/device/' + deviceId + '/keys',
    method: 'get'
  })
}

// 默认导出对象，保持与原有API类似的接口
const deviceAPI = {
  getDeviceList,
  getDeviceById,
  createDevice,
  updateDevice,
  deleteDevice,
  batchDeleteDevices,
  getDevicePage,
  updateDeviceStatus,
  getDeviceStats,
  regenerateDeviceKey,
  getDeviceKeys
}

export default deviceAPI